<?php

/**
 * @package Joomla
 * @subpackage Jmonoslideshow
 * @copyright (C) 2010 - Matthieu BARBE - www.ccomca.com
 * @license GNU/GPL v2
 * 
 * Jmonoslideshow is a Joomla extension for Monoslideshow.
 *
 * Jmonoslideshow uses :
 * Monoslideshow (http://www.monoslideshow.com/)
 * Plupload (http://www.plupload.com/) by Moxicode Systems
 * json class by Michal Migurski, Matt Knapp, Brett Stimmerman
 * jquery a JavaScript Library (http://jquery.com/)
 * getid3 library (http://getid3.sourceforge.net/)
 * swfobject is an easy-to-use and standards-friendly method to embed Flash content, which utilizes one small JavaScript file (http://code.google.com/p/swfobject/)
 * Chained Selects jQuery Plugin (http://www.appelsiini.net/2010/jquery-chained-selects)
 *
 * Jmonoslideshow is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

// no direct access
defined('_JEXEC') or die('Restricted access');
jimport('joomla.language.language');

/**
 * Jmonoslideshow component helper.
 *
 * @since	2.0
 */
abstract class JmonoslideshowHelper
{
	/**
	 * Configure the Linkbar.
	 *
	 * @param	string	$submenu	the name of the current submenu
	 *
	 * @return void
	 *
	 * @since	0.0.1
	 */
	public static function addSubmenu($submenu) 
	{
		// Addsubmenu
		JSubMenuHelper::addEntry(JText::_('COM_JMONOSLIDESHOW_HOME'), 'index.php?option=com_jmonoslideshow', $submenu == 'cp');
		JSubMenuHelper::addEntry(JText::_('COM_JMONOSLIDESHOW_MEDIAS'), 'index.php?option=com_jmonoslideshow&view=medias', $submenu == 'medias');
		JSubMenuHelper::addEntry(JText::_('COM_JMONOSLIDESHOW_CATEGORIES'), 'index.php?option=com_categories&view=categories&extension=com_jmonoslideshow', $submenu == 'categories');
		JSubMenuHelper::addEntry(JText::_('COM_JMONOSLIDESHOW_TAGS'), 'index.php?option=com_jmonoslideshow&view=tags', $submenu == 'tags');
		JSubMenuHelper::addEntry(JText::_('COM_JMONOSLIDESHOW_MODELS'), 'index.php?option=com_jmonoslideshow&view=slideshows', $submenu == 'slideshows');

		// set some global property
		$document = JFactory::getDocument();
		$document->setTitle(JText::sprintf('COM_JMONOSLIDESHOW_PAGETITLE', JFactory::getConfig()->get('sitename'), JText::_('COM_JMONOSLIDESHOW_PAGETITLE_' . $submenu)));
		
		//check
		if (!file_exists(JPATH_SITE . DS . "media". DS ."com_jmonoslideshow". DS ."swf". DS ."monoslideshow.swf")) JFactory::getApplication()->enqueueMessage( JText::_( 'COM_JMONOSLIDESHOW_MONOSLIDESHOW_FLASH_IS_NOT_INSTALLED' ), 'notice' );
		
	}

	public static function getActionsCategory($categoryId = 0) 
	{
		// Get the current user
		$user = JFactory::getUser();

		// Prepare the result
		$result = new JObject;

		if (empty($categoryId)) 
		{
			$assetName = 'com_jmonoslidehow';
		}
		else
		{
			$assetName = 'com_jmonoslidehow.category.' . (int)$categoryId;
		}

		$actions = array('core.admin', 'core.manage', 'core.create', 'core.edit', 'core.edit.own', 'core.edit.state', 'core.delete');
		foreach ($actions as $action) 
		{
			// Get the authorised actions
			$result->set($action, $user->authorise($action, $assetName));
		}
		return $result;
	}
	
	public static function getActionsImages($imageId = 0) 
	{
		// Get the current user
		$user = JFactory::getUser();

		// Prepare the result
		$result = new JObject;

		if (empty($imageId)) 
		{
			$assetName = 'com_jmonoslidehow';
		}
		else
		{
			$assetName = 'com_jmonoslidehow.image.' . (int)$imageId;
		}

		$actions = array('core.admin', 'core.manage', 'core.create', 'core.edit', 'core.edit.own', 'core.edit.state', 'core.delete');
		foreach ($actions as $action) 
		{
			// Get the authorised actions
			$result->set($action, $user->authorise($action, $assetName));
		}
		return $result;
	}
	
	public static function getActionsAlbum($albumId = 0) 
	{
		// Get the current user
		$user = JFactory::getUser();

		// Prepare the result
		$result = new JObject;

		if (empty($albumId)) 
		{
			$assetName = 'com_jmonoslidehow';
		}
		else
		{
			$assetName = 'com_jmonoslidehow.album.' . (int)$albumId;
		}

		$actions = array('core.admin', 'core.manage', 'core.create', 'core.edit', 'core.edit.own', 'core.edit.state', 'core.delete');
		foreach ($actions as $action) 
		{
			// Get the authorised actions
			$result->set($action, $user->authorise($action, $assetName));
		}
		return $result;
	}
	
	public static function getActionsModel($modelId = 0) 
	{
		// Get the current user
		$user = JFactory::getUser();

		// Prepare the result
		$result = new JObject;

		if (empty($modelId)) 
		{
			$assetName = 'com_jmonoslidehow';
		}
		else
		{
			$assetName = 'com_jmonoslidehow.model.' . (int)$modelId;
		}

		$actions = array('core.admin', 'core.manage', 'core.create', 'core.edit', 'core.edit.own', 'core.edit.state', 'core.delete');
		foreach ($actions as $action) 
		{
			// Get the authorised actions
			$result->set($action, $user->authorise($action, $assetName));
		}
		return $result;
	}

	
}
